package com.xy.manage.dao.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.xy.common.page.Pagination;
import com.xy.core.dao.impl.BaseDaoImpl;
import com.xy.manage.dao.TsurveypartnerDao;
import com.xy.manage.model.Tsurveypartner;

public class TsurveypartnerDaoImpl extends BaseDaoImpl<Tsurveypartner> implements TsurveypartnerDao {
	public TsurveypartnerDaoImpl() {
		super(Tsurveypartner.class);
	}
   
   
	@Override
	public List<Tsurveypartner> getTsurveypartner(Map<String, Object> map) {
		Object[] values = map.values().toArray();
		List<Tsurveypartner> localList = findByHql(getHql(map)+" order by partnerid desc", values);
		return localList;
	}

	@Override
	public Pagination getTsurveypartnerByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		Object[] values = map.values().toArray();
		return findByPage(getHql(map)+" order by partnerid desc", values, pageNo, pageSize);
	}

	private String getHql(Map<String, Object> map) {
		StringBuffer str = new StringBuffer("from Tsurveypartner tt");
		if(map.size()>0)str.append(" where ");
		Set<String> set = map.keySet();
		StringBuffer where = new StringBuffer();
		for (String name : set) {
			if (where.length() > 0)
				where.append(" and  ");
			where.append("tt.").append(name).append("=?");
		}
		return str.append(where.toString()).toString();
	}   
}